package main

import (
	baseLog "gitee.com/zaiqiang231/go-base-app/base_app/log"
	"gitee.com/zaiqiang231/go-base-app/base_app/store"
	"gitee.com/zaiqiang231/go-base-app/base_app/store/initdb"
	"gitee.com/zaiqiang231/go-base-app/example/model"
)

func InitDb() {
	//store.RegisterInit(initdb.DbTable[model.TestModel]{})
	store.RegisterInit(initTestModel{})

	store.GetDataStore().CreateTables()
}

type initTestModel struct {
	initdb.DbTable[model.TestModel]
}

func (i initTestModel) GetTable() store.TableInterface {
	return model.TestModel{}
}

func (i initTestModel) InitData(ds *store.Datastore) {
	var user = model.TestModel{Name: "admin", Age: 18, Sex: 1}
	err := ds.DB.Create(&user).Error
	if err != nil {
		baseLog.Errorf("initTestModel InitData Create fail, %v", err)
		return
	}
}
